package com.tianzeculture.stagebao.activity.mine;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.bean.ReplyBean;
import com.tianzeculture.stagebao.net.OtherRestUsage;
import com.tianzeculture.stagebao.network.Request;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.network.util.ToastUtil;
import com.tianzeculture.stagebao.util.SpUtils;
import com.tianzeculture.stagebao.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.rong.imlib.IFwLogCallback;

/**
 * Created by Administrator on 2018/9/29.
 */

public class SettingReplyActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvSubtitle)
    TextView tvSubtitle;
    @BindView(R.id.switchButton)
    Switch switchButton;
    @BindView(R.id.tvContent)
    EditText tvContent;
    @BindView(R.id.btnLogin)
    Button btnLogin;

    private int setReplyId = 8;
    private int getReplyId = 9;

    @Request
    OtherRestUsage otherRestUsage = null;

    @Override
    protected int getLayoutResID() {
        return R.layout.set_reply_activity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void initUI() {
        super.initUI();
        otherRestUsage.getReply(getReplyId, Util.Rid);
//        if ((boolean) (SpUtils.get(this, "isReply", false)))
//            switchButton.setChecked(true);
//        else switchButton.setChecked(false);

    }

    @OnClick(R.id.btnLogin)
    public void onViewClicked() {
        if (switchButton.isChecked()) {
            if (TextUtils.isEmpty(tvContent.getText())) {
                ToastUtil.showShort(this, "自动回复内容不能为空");
                return;
            }
            otherRestUsage.setReply(setReplyId, "1", tvContent.getText().toString().trim());
        } else {
            otherRestUsage.setReply(setReplyId, "0", tvContent.getText().toString().trim());
        }
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
        if (taskId == setReplyId) {
            if (msg.getData()){
                ToastUtil.showShort(this,msg.getMessage());
                finish();
            }
        }
        if (taskId == getReplyId) {
            if (msg.getData()) {
                ReplyBean replyBean = (ReplyBean) msg.getObj();
                if (replyBean.getAutoResponse() == 1)
                    switchButton.setChecked(true);
                else switchButton.setChecked(false);
                tvContent.setText(replyBean.getResponseMsg());
            }
        }
    }
}
